import request from "@/service";
import type { RoleQueryParams, RoleForm, RolePermission } from '@/types/role';

// 获取角色列表
export const getRoles = (params: RoleQueryParams) => {
  return request.post('/api/role/list', params);
};

// 添加角色
export const addRole = (data: RoleForm) => {
  return request.post('/api/role/add', data);
};

// 修改角色
export const updateRole = (data: RoleForm) => {
  return request.put('/api/role/edit', data);
};

// 删除角色
// 删除角色
export const deleteRole = (roleIds: number | number[]) => {
  // 统一转换为数组形式
  const ids = Array.isArray(roleIds) ? roleIds : [roleIds];
  return request.delete('/api/role/delete', { data: ids });
};

// 获取角色权限
export const getRolePermissions = (roleId: number) => {
  return request.get(`/api/privilege/getByRoleId/${roleId}`);
};

// 保存角色权限
export const saveRolePermissions = (data: RolePermission) => {
  return request.post('/api/privilege/save', data);
};

// 获取所有菜单
export const getAllMenus = () => {
  return request.get('/menu/getAllMenus');
};
